package main

import (
	"fmt"
	"sync"
)

func send(in chan int, done chan bool, wg *sync.WaitGroup) {
	for i := 0; i < 5; i++ {
		in <- i
		fmt.Printf("123")
		// 等待消费者，发送处理完的请求
		<- done
	}
	wg.Done()
}

func receive(in chan int, done chan bool, wg *sync.WaitGroup) {
	for i := 0; i < 5; i++ {
		<- in
		fmt.Printf("abc")
		// 向生产者发送接收成功的信号
		done <- true
	}
	wg.Done()
}

func main() {
	// 创建 channel
	in := make(chan int)
	done := make(chan bool)
	// 创建 wg *sync.WaitGroup
	var wg sync.WaitGroup
	// 添加两个任务
	wg.Add(2)
	// 启动
	go send(in, done, &wg)
	go receive(in, done, &wg)
	// 等待任务执行结束
	wg.Wait()
	fmt.Println("任务执行结束")
}
